From f064b66c64fc6d594374b7bfba696905cd58cfcd Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sat, 6 May 2006 21:41:53 +0000 Subject: [PATCH] (bug 5841) Allow the 'EditFilter' hook to return a non-fatal error message --- RELEASE-NOTES | 2 +- docs/hooks.txt | 11 +++++++++++ includes/EditPage.php | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 8b0ca36ab6..5eb22afd08 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -220,7 +220,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 5839) Prevent access to Special:Confirmemail for logged-out users * (bug 5853) Update for Portuguese messages (pt) * (bug 5851) Use Cyrillic for Kirghiz language name - +* (bug 5841) Allow the 'EditFilter' hook to return a non-fatal error message == Compatibility == diff --git a/docs/hooks.txt b/docs/hooks.txt index a8bfd5b6b1..3c46368d35 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -297,6 +297,17 @@ $user: the user _doing_ the block (not the one being blocked) $block: the Block object that was saved $user: the user who did the block (not the one being blocked) +'EditFilter': Perform checks on an edit +$editor: Edit form (see includes/EditPage.php) +$text: Contents of the edit box +§ion: Section being edited +$error: Error message to return + +Return false to halt editing; you'll need to handle error messages, etc. yourself. +Alternatively, modifying $error and returning true will cause the contents of $error +to be echoed at the top of the edit form as wikitext. Return true without altering +$error to allow the edit to proceed. + 'EmailConfirmed': When checking that the user's email address is "confirmed" $user: User being checked $confirmed: Whether or not the email address is confirmed diff --git a/includes/EditPage.php b/includes/EditPage.php index 90bc1351e8..b14b1c8d73 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -30,6 +30,7 @@ class EditPage { var $missingSummary = false; var $allowBlankSummary = false; var $autoSumm = ''; + var $hookError = ''; # Form values var $save = false, $preview = false, $diff = false; @@ -492,11 +493,16 @@ class EditPage { wfProfileOut( "$fname-checks" ); return false; } - if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1, $this->section ) ) ) { - # Error messages or other handling should be performed by the filter function + if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1, $this->section, &$this->hookError ) ) ) { + # Error messages etc. could be handled within the hook... wfProfileOut( $fname ); wfProfileOut( "$fname-checks" ); return false; + } elseif( $this->hookError != '' ) { + # ...or the hook could be expecting us to produce an error + wfProfileOut( "$fname-checks " ); + wfProfileOut( $fname ); + return false; } if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) { # Check block state against master, thus 'false'. @@ -771,6 +777,10 @@ class EditPage { if( $this->missingSummary ) { $wgOut->addWikiText( wfMsg( 'missingsummary' ) ); } + + if( !$this->hookError = '' ) { + $wgOut->addWikiText( $this->hookError ); + } if ( !$this->checkUnicodeCompliantBrowser() ) { $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') ); -- 2.20.1